package com.glh.javalogic.common;


import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.glh.javalogic.R;
import com.glh.javalogic.chapter4.chapter_4Activity;
import com.glh.javalogic.chapter5.chapter_5Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * author : 高磊华
 * e-mail : 984992087@qq.com
 * time   : 2018\6\9
 * desc   : 进入到各个章节代码的主入口
 */

public class MainActivity extends BaseActivity {

    private ListView     mListView;
    private List<String> chapterList;

    @Override
    protected int getContentResourseId() {
        return R.layout.activity_main;
    }

    @Override
    protected void init() {

        mListView = (ListView) findViewById(R.id.listview);

        chapterList = new ArrayList<>();
        chapterList.add("第1章(期待中)");
        chapterList.add("第2章(期待中)");
        chapterList.add("第3章(期待中)");
        chapterList.add("第4章(类的继承)");
        chapterList.add("第5章(类的拓展)");

        ChapterAdapter adapter = new ChapterAdapter(context, R.layout
                .item_main_chapter, chapterList);

        mListView.setAdapter(adapter);

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position+1) {
                    case 1:
                    case 2:
                    case 3:
                        Toast.makeText(context, "开发中", Toast.LENGTH_SHORT).show();
                        break;
                    case 4:
                        JumpToActivity(chapter_4Activity.class);
                        break;
                    case 5:
                        JumpToActivity(chapter_5Activity.class);
                        break;
                }
            }
        });
    }
}

